package com.twu.biblioteca;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.List;

/**
 * Created by thoughtworker on 1/15/14.
 */
public class Circulation {
    ConsolePrinter consolePrinter;
    BufferedReader bufferedReader;
    List<Book> bookList;
    public int userMenuChoice;

    public Circulation(BufferedReader bufferedReader, ConsolePrinter consolePrinter, List<Book> bookList) {
        this.bufferedReader = bufferedReader;
        this.consolePrinter = consolePrinter;
        this.bookList = bookList;
    }

    public void start(){
        printInitialInformation();
        displayMenu();
        getResponse();

    }

    public void printInitialInformation() {
        welcome();
        displayBookList();
    }

    public void welcome(){
        consolePrinter.welcomeMessage();
    }

    public void displayBookList(){
        consolePrinter.printBookList(bookList);
    }

    public void displayMenu(){
        consolePrinter.printMenu();
    }

    public void getResponse(){
        userMenuChoice = -1;
        while (userMenuChoice != 1) {
            try {
                userMenuChoice = Integer.parseInt(bufferedReader.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (userMenuChoice == 1){
                displayBookList();
            } else {
                consolePrinter.printMenuInputError();
            }
        }
    }


}
